package com.hulk.dryad.common.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.EnumSet;

/**
 * @author kim
 * @date 2020-01-19
 * <p>
 * 前端类型类型
 */
@Getter
@AllArgsConstructor
public enum StyleType {



	/**
	 * 前端类型-avue 风格
	 */
	AVUE("0", "StyleType_AVUE"),

	/**
	 * 前端类型-element 风格
	 */
	ELEMENT("1", "StyleType_ELEMENT");

	/**
	 * 类型
	 */
	private String style;

	/**
	 * 描述
	 */
	private String description;

	StyleType(String style, String description) {
		this.style = style;
		this.description = description;
	}

	public String getDesc() {
		return messageSource.getMessage(description, null, description, LocaleContextHolder.getLocale());
	}


	private MessageSource messageSource;

	public StyleType setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
		return this;
	}


	@Component
	public static class ReportTypeServiceInjector {

		@Resource
		private MessageSource messageSource;

		@PostConstruct
		public void postConstruct() {
			for (StyleType ec : EnumSet.allOf(StyleType.class)) {
				ec.setMessageSource(messageSource);
			}
		}
	}

}
